package tirtilcam.controller;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ItemListener;
import java.io.FileNotFoundException;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.SoftBevelBorder;

import tirtilcam.model.ImageChangeEvent;
import tirtilcam.model.TirtilCamStreamer;
import tirtilcam.view.TirtilCamPanel;
import tirtilcam.view.SixChoicePanel;
import tirtilcam.view.WindowUtilities;



public class TirtilCamViewer extends JFrame implements tirtilcam.model.ImageChangeListener
{

	ItemListener buttonDisplayListener = null;
	ItemListener buttonPadListener = null;

	// Premade convenience dimensions, for use wherever you need 'em.
	public static Dimension HGAP2 = new Dimension(2, 1);
	public static Dimension VGAP2 = new Dimension(1, 2);

	public static Dimension HGAP5 = new Dimension(5, 1);
	public static Dimension VGAP5 = new Dimension(1, 5);

	public static Dimension HGAP10 = new Dimension(10, 1);
	public static Dimension VGAP10 = new Dimension(1, 10);

	public static Dimension HGAP15 = new Dimension(15, 1);
	public static Dimension VGAP15 = new Dimension(1, 15);

	public static Dimension HGAP20 = new Dimension(20, 1);
	public static Dimension VGAP20 = new Dimension(1, 20);

	public static Dimension HGAP25 = new Dimension(25, 1);
	public static Dimension VGAP25 = new Dimension(1, 25);

	public static Dimension HGAP30 = new Dimension(30, 1);
	public static Dimension VGAP30 = new Dimension(1, 30);
	
	private List<TirtilCamStreamer> camList = null;
	
	Border loweredBorder = new CompoundBorder(new SoftBevelBorder(
			SoftBevelBorder.LOWERED), new EmptyBorder(5, 5, 5, 5));
	
	EmptyBorder border5 = new EmptyBorder(5, 5, 5, 5);
	


	public static void main(String[] args) throws FileNotFoundException
	{
		TirtilCamViewer mW = new TirtilCamViewer();
		mW.setVisible(true);
	}

	public TirtilCamViewer() throws FileNotFoundException
	{

		WindowUtilities.setMotifLookAndFeel();
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(800, 600);
		setVisible(true);

		setBackground(Color.lightGray);
		JPanel controlArea = new JPanel(new GridLayout(3, 1));
		String[] colors =
		{ "Red", "Green", "Blue", "Black", "White", "Gray" };
		controlArea.add(new SixChoicePanel("Color", colors));
		String[] thicknesses =
		{ "1", "2", "3", "4", "5", "6" };
		controlArea.add(new SixChoicePanel("Line Thickness", thicknesses));
		String[] fontSizes =
		{ "10", "12", "14", "18", "24", "36" };
		//controlArea.add(new SixChoicePanel("Font Size", fontSizes));
		//add(controlArea, BorderLayout.EAST);
		
		Container m_container = this.getContentPane();
		m_container.setLayout(new GridLayout(2,6));
		
		JPanel camPanel1 = new TirtilCamPanel("CamPanel1",m_container);
		JPanel camPanel2 = new TirtilCamPanel("CamPanel2",m_container);
		JPanel camPanel3 = new TirtilCamPanel("CamPanel3",m_container);
		JPanel camPanel4 = new TirtilCamPanel("CamPanel4",m_container);
		
	
		//TirtilCam tCam2 = new TirtilCam(camPanel,"http://85.103.173.236:31339/img/mjpeg.cgi");
		//TirtilCam tCam1 = new TirtilCam(camPanel,"http://24.249.24.110:2001/axis-cgi/mjpg/video.cgi");
		TirtilCamStreamer tCam1 = new TirtilCamStreamer("Tirtil1",camPanel1,"http://24.249.24.110:2001/axis-cgi/mjpg/video.cgi");
		TirtilCamStreamer tCam2 = new TirtilCamStreamer("Tirtil2",camPanel2,"http://85.103.173.236:31339/img/mjpeg.cgi");
		TirtilCamStreamer tCam3 = new TirtilCamStreamer("Tirtil3",camPanel3,"http://85.103.173.236:31339/img/mjpeg.cgi");
		TirtilCamStreamer tCam4 = new TirtilCamStreamer("Tirtil4",camPanel4,"http://24.249.24.110:2001/axis-cgi/mjpg/video.cgi");
		//TirtilCamStreamer tCam2 = new TirtilCamStreamer("Tirtil2",camPanel2,"http://85.103.173.236:31339/img/mjpeg.cgi");
		
		tCam1.addImageChangeListener(this);
		
		m_container.add(camPanel1);
		m_container.add(camPanel2);
		m_container.add(camPanel3);
		m_container.add(camPanel4);
		
		new Thread(tCam1).start();
		new Thread(tCam2).start();
		new Thread(tCam3).start();
		new Thread(tCam4).start();
		//m_container.add(camPanel2);
		//new Thread(tCam2).start();
				

		pack();
		show();
	}

	public JPanel createHorizontalPanel(boolean threeD)
	{
		JPanel p = new JPanel();
		p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
		p.setAlignmentY(TOP_ALIGNMENT);
		p.setAlignmentX(LEFT_ALIGNMENT);
		if (threeD)
		{
			p.setBorder(loweredBorder);
		}
		return p;
	}

	public JPanel createVerticalPanel(boolean threeD)
	{
		JPanel p = new JPanel();
		p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
		p.setAlignmentY(TOP_ALIGNMENT);
		p.setAlignmentX(LEFT_ALIGNMENT);
		if (threeD)
		{
			p.setBorder(loweredBorder);
		}
		return p;
	}

	@Override
	public void imageChanged(ImageChangeEvent evt)
	{
	    // TODO Auto-generated method stub
	    
	}

}
